/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Entity.*;
import Model.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import library.Koneksi;
import library.StatusBimbingan;


/**
 *
 * @author mr2
 */
public class BimbinganTALogic{
    HttpServletRequest request;

    public BimbinganTALogic(HttpServletRequest request) {
        this.request = request;
    }
    
    public String ListPembimbing(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            
            
            DosenModel listDosen = new DosenModel();          
            List<Dosen> pembimbing = listDosen.ListPembimbing();
            ArrayList listPembimbing = new ArrayList();
            
            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
             
            for(int i=0; i < pembimbing.size(); i++){
                
                Map map = new HashMap();
                map.put("idUser", pembimbing.get(i).getUser().getIdUser());
                map.put("namaUser", pembimbing.get(i).getUser().getNamaUser());               
                map.put("jlhMhsPembimbing1", bimbinganTA.JlhMhsPembimbing1(pembimbing.get(i).getUser().getIdUser()));
                map.put("jlhMhsPembimbing2", bimbinganTA.JlhMhsPembimbing2(pembimbing.get(i).getUser().getIdUser()));
                map.put("statusPembimbing1", pembimbing.get(i).getStatusPembimbing1());
                
                listPembimbing.add(map);
            }
            

            request.setAttribute("listPembimbing", listPembimbing);
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "kelolaPembimbing");

            return "monta/KoorTA_kelola_pembimbing.jsp";
        }
    }
    
    public String setPembimbing1(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idUser = request.getParameter("idUser");
            String statusPembimbing1 = request.getParameter("statusPembimbing1");
            System.out.println("tatusPembimbing1 = "+statusPembimbing1);
            System.out.println("id user = "+idUser);
            User user = new User();
            Dosen dosen = new Dosen();
            DosenModel pembimbing1 = new DosenModel();

            user.setIdUser(idUser);
            dosen.setUser(user);
            dosen.setStatusPembimbing1(statusPembimbing1);

            pembimbing1.setPembimbing1(dosen);

            return ListPembimbing();
        }
    }
    
    //Menampilkan list bimbingan yang telah dicatat pada akun mahasiswa
    public String MhsListBimbingan(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("mahasiswa"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idMahasiswa = (String) session.getAttribute("id_user");
        
            User user = new User();
            user.setIdUser(idMahasiswa);

            TAModel TA = new TAModel();
            int idTA = TA.getIdTA(user);

            TA ta = new TA();
            ta.setUser(user);
            ta.setIdTA(idTA);

            String pesan = request.getParameter("pesan");
            String judulBimbingan = request.getParameter("judulBimbingan");
            request.setAttribute("judulBimbingan", judulBimbingan);
            request.setAttribute("pesan", pesan);
            request.setAttribute("idMahasiswa", idMahasiswa);
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "bimbinganTA");

            SidangTAModel detailSidang = new SidangTAModel();
            String statusDaftarProposal = detailSidang.getStatusDaftarProposal(ta);
//            String statusDaftarProgress = detailSidang.getStatusDaftarProgress(ta);
            String statusDaftarFinal = detailSidang.getStatusDaftarFinal(ta);
            String statusSidangProposal = detailSidang.getStatusSidangProposal(ta);

            if("SUDAH DAFTAR PROPOSAL".equals(statusDaftarProposal)){

            if("DITERIMA".equals(statusSidangProposal)||"DITERIMA DENGAN REVISI".equals(statusSidangProposal)){

                BimbinganTAModel list = new BimbinganTAModel();
                List<BimbinganTA> listBimbinganTA = list.ListBimbinganTA(idMahasiswa);

                DosenModel pembimbing = new DosenModel();
                List<Dosen> listPembimbing2 = pembimbing.ListPembimbing();

                request.setAttribute("listBimbinganTA", listBimbinganTA);
                request.setAttribute("idTA", idTA);
                request.setAttribute("listPembimbing2", listPembimbing2);
                return "monta/Mhs_list_bimbingan.jsp";
            }else{
                return "monta/Mhs_list_bimbingan_hidden.jsp";
            }

            }else{
                return "monta/Mhs_list_bimbingan_hidden.jsp";
            } 
        }
    }
    
    //Menampilkan halaman pengisian form bimbingan pada akun mahasiswa
    public String formBimbinganTA(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("mahasiswa"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idUser = (String) session.getAttribute("id_user");
        
            User user = new User();
            user.setIdUser(idUser);

            TAModel TA = new TAModel();
            TAModel detailTA = new TAModel();
            int idTA = TA.getIdTA(user);

            request.setAttribute("idUser", idUser);
            request.setAttribute("idTA", idTA);

            TA ta = new TA();
            ta.setIdTA(idTA);

            DosenModel pembimbing = new DosenModel();
            List<Dosen> listPembimbing1 = pembimbing.ListPembimbing1();
            List<Dosen> listPembimbing2 = pembimbing.ListPembimbing();
            request.setAttribute("listPembimbing1", listPembimbing1);
            request.setAttribute("listPembimbing2", listPembimbing2);

            String pembimbing1 = detailTA.getDetailDataTA(ta).getPembimbing1();
            String pembimbing2 = detailTA.getDetailDataTA(ta).getPembimbing2();
            request.setAttribute("pembimbing1", pembimbing1);
            request.setAttribute("pembimbing2", pembimbing2);

            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "bimbinganTA");

            return "monta/Mhs_form_bimbingan.jsp";
        }
        
    }
    
    //Melakukan perekaman bimbingan TA pada akun mahasiswa
    public String catatBimbinganTA(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("mahasiswa"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            BimbinganTAModel catatBimbingan = new BimbinganTAModel();
        
            String id_ta = request.getParameter("idTA");
            String judulBimbingan = request.getParameter("judulBimbingan");
            String tglBimbingan = request.getParameter("tglBimbingan");
            String isiBimbingan = request.getParameter("isiBimbingan");
            String pembimbing = request.getParameter("pembimbing");
            String pesan = null;

            if(id_ta != null){
                BimbinganTA bimbinganTA = new BimbinganTA();
                User pembimbingTA = new User();
                pembimbingTA.setIdUser(pembimbing);

                TA ta = new TA();
                int idTA = Integer.parseInt(id_ta);
                ta.setIdTA(idTA);

                bimbinganTA.setTa(ta);
                bimbinganTA.setTglBimbingan(tglBimbingan);
                bimbinganTA.setJudulBimbingan(judulBimbingan);
                bimbinganTA.setIsiBimbingan(isiBimbingan);
                bimbinganTA.setUser(pembimbingTA);

                boolean CatatBimbingan = catatBimbingan.CatatBimbingan(bimbinganTA);

                if(CatatBimbingan){
                    pesan = "sukses catat";
                }else{
                    pesan = "gagal catat";
                }

                return "SidangTAController?page=listBimbinganTA&&pesan="+pesan+"&&judulBimbingan=="+judulBimbingan;  
            }else{
                return MhsListBimbingan();
            }
        }
    }
    
    //Menampilkan list NRP mahasiswa bimbingan pada akun dosen
    public String DosenListMhsBimbingan(){
        
        String statusPembimbing = request.getParameter("statusPembimbing");
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("dosen"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            
            String idDosen = (String) session.getAttribute("id_user");

            DosenModel dosen = new DosenModel();
            List<Dosen> pembimbing = dosen.ListPembimbing();
            request.setAttribute("pembimbing", pembimbing);
            request.setAttribute("idDosen", idDosen);
            request.setAttribute("statusPembimbing", statusPembimbing);
            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
            List<TA> listMhsBimbingan = bimbinganTA.ListMhsBimbingan(idDosen, statusPembimbing);

            request.setAttribute("listMhsBimbingan", listMhsBimbingan);

            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "mahasiswaBimbingan");

            return "monta/Dosen_list_mhsBimbingan.jsp";
        }
    }
    
    //Menampilkan list bimbingan yang telah dicatat mahasiswa tertentu pada akun dosen
    public String DosenListBimbinganMhs(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("dosen"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String id_ta = request.getParameter("idTA");
            String idDosen = request.getParameter("idDosen");
            String idMahasiswa = request.getParameter("idMahasiswa");
            String pesan = request.getParameter("pesan");
            String judulBimbingan = request.getParameter("judulBimbingan");
            request.setAttribute("judulBimbingan", judulBimbingan);
            request.setAttribute("pesan", pesan);

            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "mahasiswaBimbingan");

            if(idDosen != null){

                User user = new User();
                user.setIdUser(idMahasiswa);

                TAModel dataTA = new TAModel();
                int idTA = dataTA.getIdTA(user);
                TA ta = new TA();


                request.setAttribute("idDosen", idDosen);
                request.setAttribute("idMahasiswa", idMahasiswa);
                request.setAttribute("idTA", idTA);

                DosenModel dosen = new DosenModel();
                List<Dosen> pembimbing = dosen.ListPembimbing();
                request.setAttribute("pembimbing", pembimbing);

                BimbinganTAModel bimbinganTA = new BimbinganTAModel();
                List<BimbinganTA> listBimbinganTA = bimbinganTA.ListBimbinganTA(idMahasiswa);
                request.setAttribute("listBimbinganTA", listBimbinganTA);

                return "monta/Dosen_list_bimbinganMhs.jsp";
            }else{
                return "monta/Dosen_list_bimbinganMhs.jsp";
            }
        }
    }
    
    public String MhsDetailBimbingan(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("mahasiswa"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idBim = request.getParameter("idBim");
            String idMahasiswa = request.getParameter("idMahasiswa");
            request.setAttribute("idBim", idBim);
            request.setAttribute("idMahasiswa", idMahasiswa);

            DosenModel dosen = new DosenModel();
            List<Dosen> pembimbing = dosen.ListPembimbing();
            request.setAttribute("pembimbing", pembimbing);

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
            BimbinganTA detailBimbingan = bimbinganTA.DetailBimbingan(idBim);
            request.setAttribute("detailBimbingan", detailBimbingan);

            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "bimbinganTA");

            return "monta/Mhs_detail_bimbingan.jsp";
        }
    }
    
    public String DosenDetailBimbinganMhs(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("dosen"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idBim = request.getParameter("idBim");
            String idMahasiswa = request.getParameter("idMahasiswa");
            String idDosen = request.getParameter("idDosen");
            request.setAttribute("idMahasiswa", idMahasiswa);
            request.setAttribute("idDosen", idDosen);
            request.setAttribute("idBim", idBim);

            DosenModel dosen = new DosenModel();
            List<Dosen> pembimbing = dosen.ListPembimbing();
            request.setAttribute("pembimbing", pembimbing);

            StatusBimbingan statusBimbingan = new StatusBimbingan();
            List<StatusBimbingan>  status = statusBimbingan.StatusBimbingan();
            request.setAttribute("status", status);

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
            BimbinganTA detailBimbingan = bimbinganTA.DetailBimbingan(idBim);
            request.setAttribute("detailBimbingan", detailBimbingan);

            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "mahasiswaBimbingan");

            return "monta/Dosen_detail_bimbinganMhs.jsp";
        }
    }
    
    public String UpdateBimbingan(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("mahasiswa"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idMahasiswa = request.getParameter("idMahasiswa");
            String idBimbingan = request.getParameter("idBim");
            BimbinganTAModel update = new BimbinganTAModel();
            BimbinganTA bimbinganTA = new BimbinganTA();

            String pesan = null;

            if(idBimbingan != null){            

                String judulBimbingan = request.getParameter("judulBimbingan");
                String isiBimbingan = request.getParameter("isiBimbingan");
                int idBim = Integer.parseInt(idBimbingan);

                bimbinganTA.setIdBimbingan(idBim);
                bimbinganTA.setJudulBimbingan(judulBimbingan);
                bimbinganTA.setIsiBimbingan(isiBimbingan);

                boolean UpdateDataBimbingan = update.UpdateDataBimbingan(bimbinganTA);

                if(UpdateDataBimbingan){
                    pesan = "sukses update";
                }else{
                    pesan = "gagal update";
                }
                System.out.println(pesan);


                return "SidangTAController?page=listBimbinganTA&&idMahasiswa="+idMahasiswa+"&&pesan="+pesan+"&&judulBimbingan="+judulBimbingan;
            }else{
                return "SidangTAController?page=listBimbinganTA&&idMahasiswa="+idMahasiswa+"&&pesan="+pesan;
            }
        } 
    }
    
    public String DosenUpdateBimbingan(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("dosen"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String idDosen = request.getParameter("idDosen");
            String idMahasiswa = request.getParameter("idMahasiswa");
            String idBimbingan = request.getParameter("idBim");
            BimbinganTAModel update = new BimbinganTAModel();
            BimbinganTA bimbinganTA = new BimbinganTA();

            String pesan = null;

            if(idBimbingan != null){            

                String judulBimbingan = request.getParameter("judulBimbingan");
                String isiBimbingan = request.getParameter("isiBimbingan");
                int idBim = Integer.parseInt(idBimbingan);

                bimbinganTA.setIdBimbingan(idBim);
                bimbinganTA.setJudulBimbingan(judulBimbingan);
                bimbinganTA.setIsiBimbingan(isiBimbingan);

                boolean UpdateDataBimbingan = update.UpdateDataBimbingan(bimbinganTA);

                if(UpdateDataBimbingan){
                    pesan = "sukses update";
                }else{
                    pesan = "gagal update";
                }
                System.out.println(pesan);


                return "SidangTAController?page=listBimbinganMhs&&idMahasiswa="+idMahasiswa+"&&idDosen="+idDosen+"&&pesan="+pesan+"&&judulBimbingan="+judulBimbingan;
            }else{
                return "SidangTAController?page=listBimbinganMhs&&idMahasiswa="+idMahasiswa+"&&idDosen="+idDosen+"&&pesan="+pesan;
            } 
        }
        
        
    }
    
    public String SetujuBimbingan(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("dosen"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String statusBimbingan = request.getParameter("statusBimbingan");
            String idDosen = request.getParameter("idDosen");
            String idMahasiswa = request.getParameter("idMahasiswa");
            String idBimbingan = request.getParameter("idBim");
            BimbinganTAModel update = new BimbinganTAModel();
            BimbinganTA bimbinganTA = new BimbinganTA();

            if(idDosen != null){


                int idBim = Integer.parseInt(idBimbingan);

                bimbinganTA.setIdBimbingan(idBim);
                bimbinganTA.setStatusBimbingan(statusBimbingan);

                try{
                    update.setujuDataBimbingan(bimbinganTA);
                    }catch(Exception ex){
                        System.out.println(ex.getMessage());
                    }

                return "SidangTAController?page=listBimbinganMhs&&idDosen="+idDosen+"&&idMahasiswa="+idMahasiswa;
            }else{
                return DosenListMhsBimbingan();
            }
        }      
    }
    
    public String RekapBimbinganTA(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String laporan = request.getParameter("laporan");
            String detail = request.getParameter("detail");
            System.out.println("detail = "+detail);
            String formatTampilan = request.getParameter("formatTampilan");
            String page = "monta/KoorTA_rekap_bimbingan_TA.jsp";

            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "rekapBimbinganTA");

            if("REKAP BORANG TA".equals(laporan)){
                rekapBorang();

                if("HTML".equals(formatTampilan)){
                    return "monta/KoorTA_rekap_bimbingan_TA.jsp";
                }else if("EXCEL".equals(formatTampilan)){
                    page = "monta/KoorTA_cetakRekap_bimbingan_TA.jsp";
                }else{
                    page = "monta/KoorTA_rekap_bimbingan_TA.jsp";
                }

            }else if("RATA JUMLAH MHS BIMBINGAN".equals(laporan)){           
                
                if("1".equals(detail)){
                    detailJlhBimbingan();
                }else if("2".equals(detail)){
                    mhsBimbinganDosen();
                }else{
                    rataJlhMhsPerDosenPerPeriode();
                }
                page = "monta/KoorTA_rekap_bimbingan_TA.jsp";
            }else if("RATA LAMA TA".equals(laporan)){
                if("1".equals(detail)){
                    detailLamaTA();
                }else{
                    rataLamaTAPerPeriode();
                }
                page = "monta/KoorTA_rekap_bimbingan_TA.jsp";
            }else if("RATA PERTEMUAN BIMBINGAN".equals(laporan)){
                if("1".equals(detail)){
                    detailPertemuanBim();
                }else{
                    rataPertemuanPerPeriode();
                }
                page = "monta/KoorTA_rekap_bimbingan_TA.jsp";
            }

            System.out.println(page);
            return page;
        }
    }
    
    public String rekapBorang(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String laporan = request.getParameter("laporan");
            String periodeRekapAwal = request.getParameter("periodeRekapAwal");
            String periodeRekapAkhir = request.getParameter("periodeRekapAkhir");
            String formatTampilan = request.getParameter("formatTampilan");

            YudisiumModel periode = new YudisiumModel();
            List<Yudisium> periodeYudisium = periode.ListYudisium(0);

            DosenModel dosen = new DosenModel();
            List<Dosen> namaDosen = dosen.ListPembimbing();

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
            double RataJlhMhsPerDosen = bimbinganTA.RataJLHMhsPerDosen(periodeRekapAwal, periodeRekapAkhir);
            double RataLamaTA = bimbinganTA.RataLamaTA(periodeRekapAwal, periodeRekapAkhir);
            double RataPertemuan = bimbinganTA.RataPertemuan(periodeRekapAwal, periodeRekapAkhir);
            List<Dosen> listMhsBimbingan = bimbinganTA.JlhMhsBimbinganDosenLulus(periodeRekapAwal, periodeRekapAkhir);

            request.setAttribute("namaDosen", namaDosen);
            request.setAttribute("periodeRekapAwal", periodeRekapAwal);
            request.setAttribute("periodeRekapAkhir", periodeRekapAkhir);
            request.setAttribute("formatTampilan", formatTampilan);
            request.setAttribute("periodeYudisium", periodeYudisium);
            request.setAttribute("RataJlhMhsPerDosen", RataJlhMhsPerDosen);
            request.setAttribute("RataLamaTA", RataLamaTA);
            request.setAttribute("RataPertemuan", RataPertemuan);
            request.setAttribute("listMhsBimbingan", listMhsBimbingan);
            request.setAttribute("laporan", laporan);

            return "monta/rekapBorang.jsp";
        }
    }
    
    public String rataJlhMhsPerDosenPerPeriode(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String laporan = request.getParameter("laporan");
            String detail = request.getParameter("detail");
            System.out.println("detail = "+detail);
            String rentangPeriode = request.getParameter("rentangPeriode");
            int rentang = 0;

            if(rentangPeriode != null) rentang = Integer.parseInt(rentangPeriode) * 2;

            YudisiumModel period = new YudisiumModel();
            List<Yudisium> periodeYudisium = period.ListYudisium(rentang);

            BimbinganTAModel bimbingan = new BimbinganTAModel();
            ArrayList rataJlhBimbinganPerPeriod = new ArrayList();

            for(int i=0; i < periodeYudisium.size(); i++){

                double RataJLHMhsPerDosen = bimbingan.RataJLHMhsPerDosen(periodeYudisium.get(i).getTglMulai(), periodeYudisium.get(i).getTglAkhir());

                Map map = new HashMap();
                map.put("periode", periodeYudisium.get(i).getPeriode());
                map.put("tglMulai", periodeYudisium.get(i).getTglMulai());
                map.put("tglAkhir", periodeYudisium.get(i).getTglAkhir());
                map.put("RataJLHMhsPerDosen", RataJLHMhsPerDosen);

                rataJlhBimbinganPerPeriod.add(map);  
            }

            request.setAttribute("rataJlhBimbinganPerPeriod", rataJlhBimbinganPerPeriod);
            request.setAttribute("laporan", laporan);
            request.setAttribute("detail", detail);
            request.setAttribute("rentangPeriode", rentangPeriode);
            

            return "monta/RataJlhBimPerPeriode.jsp";
        } 
    }
    
    public String detailJlhBimbingan(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            
            String laporan = request.getParameter("laporan");
            String detail = request.getParameter("detail");
            String periode = request.getParameter("periode");
            String periodeRekapAwal = request.getParameter("periodeRekapAwal");
            String periodeRekapAkhir = request.getParameter("periodeRekapAkhir");

            DosenModel dosen = new DosenModel();
            List<Dosen> namaDosen = dosen.ListPembimbing();

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
//            List<Dosen> listMhsBimbingan = bimbinganTA.JlhMhsBimbinganDosen(periodeRekapAwal, periodeRekapAkhir);
            ArrayList listMhsBimbingan = bimbinganTA.JlhMhsBimbinganDosenLulus(periodeRekapAwal, periodeRekapAkhir);
            
            request.setAttribute("namaDosen", namaDosen);
            request.setAttribute("listMhsBimbingan", listMhsBimbingan);
            request.setAttribute("periode", periode);
            request.setAttribute("laporan", laporan);
            request.setAttribute("detail", detail);
            request.setAttribute("periodeRekapAwal", periodeRekapAwal);
            request.setAttribute("periodeRekapAkhir", periodeRekapAkhir);
            
            return "monta/DetailJlhBimbingan.jsp";
        } 
    }
    
    public String mhsBimbinganDosen(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            
            String laporan = request.getParameter("laporan");
            String detail = request.getParameter("detail");
            String idDosen = request.getParameter("idDosen");
            String periode = request.getParameter("periode");
            String periodeRekapAwal = request.getParameter("periodeRekapAwal");
            String periodeRekapAkhir = request.getParameter("periodeRekapAkhir");

            MahasiswaModel mahasiswa = new MahasiswaModel();
            List<Mahasiswa> namaMahasiswa = mahasiswa.ListMahasiswa();
            
            DosenModel dosen = new DosenModel();
            List<Dosen> namaDosen = dosen.ListPembimbing();

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
            List<TA> MhsBimbinganDosen = bimbinganTA.MhsBimbinganDosenLulus(idDosen, periodeRekapAwal, periodeRekapAkhir);
            System.out.println("jumlah mhs bimibngan :"+MhsBimbinganDosen.size());
            request.setAttribute("namaMahasiswa", namaMahasiswa);
            request.setAttribute("namaDosen", namaDosen);
            request.setAttribute("idDosen", idDosen);
            request.setAttribute("MhsBimbinganDosen", MhsBimbinganDosen);
            request.setAttribute("periode", periode);
            request.setAttribute("laporan", laporan);
            request.setAttribute("detail", detail);
            request.setAttribute("periodeRekapAwal", periodeRekapAwal);
            request.setAttribute("periodeRekapAkhir", periodeRekapAkhir);
            
            return "monta/MhsBimbinganDosen.jsp";
        } 
    }
    
    public String rataLamaTAPerPeriode(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String laporan = request.getParameter("laporan");
            String rentangPeriode = request.getParameter("rentangPeriode");
            int rentang = 0;

            if(rentangPeriode != null) rentang = Integer.parseInt(rentangPeriode) * 2;

            YudisiumModel period = new YudisiumModel();
            List<Yudisium> periodeYudisium = period.ListYudisium(rentang);

            BimbinganTAModel bimbingan = new BimbinganTAModel();
            ArrayList RataLamaTAPerPeriode = new ArrayList();

            for(int i=0; i < periodeYudisium.size(); i++){

                double RataLamaTA = bimbingan.RataLamaTA(periodeYudisium.get(i).getTglMulai(), periodeYudisium.get(i).getTglAkhir());

                Map map = new HashMap();
                map.put("periode", periodeYudisium.get(i).getPeriode());
                map.put("tglMulai", periodeYudisium.get(i).getTglMulai());
                map.put("tglAkhir", periodeYudisium.get(i).getTglAkhir());
                map.put("RataLamaTA", RataLamaTA);

                RataLamaTAPerPeriode.add(map);  
            }

            request.setAttribute("RataLamaTAPerPeriode", RataLamaTAPerPeriode);
            request.setAttribute("laporan", laporan);
            request.setAttribute("rentangPeriode", rentangPeriode);

            return "monta/RataLamaTAPerPeriode.jsp";   
        }
    }
    
    public String detailLamaTA(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            
            String laporan = request.getParameter("laporan");
            String detail = request.getParameter("detail");
            String periode = request.getParameter("periode");
            String periodeRekapAwal = request.getParameter("periodeRekapAwal");
            String periodeRekapAkhir = request.getParameter("periodeRekapAkhir");

            MahasiswaModel mahasiswa = new MahasiswaModel();
            List<Mahasiswa> namaMahasiswa = mahasiswa.ListMahasiswa();

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
//            List<TA> listLamaTA = bimbinganTA.ListLamaTA(periodeRekapAwal, periodeRekapAkhir);
            ArrayList listLamaTA = bimbinganTA.ListLamaTA(periodeRekapAwal, periodeRekapAkhir);
            
            request.setAttribute("namaMahasiswa", namaMahasiswa);
            request.setAttribute("listLamaTA", listLamaTA);
            request.setAttribute("periode", periode);
            request.setAttribute("laporan", laporan);
            request.setAttribute("detail", detail);
            request.setAttribute("periodeRekapAwal", periodeRekapAwal);
            request.setAttribute("periodeRekapAkhir", periodeRekapAkhir);
            
            return "monta/DetailLamaTA.jsp";
        } 
    }
    
    public String rataPertemuanPerPeriode(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            String laporan = request.getParameter("laporan");
            String rentangPeriode = request.getParameter("rentangPeriode");
            int rentang = 0;

            if(rentangPeriode != null) rentang = Integer.parseInt(rentangPeriode) * 2;

            YudisiumModel period = new YudisiumModel();
            List<Yudisium> periodeYudisium = period.ListYudisium(rentang);

            BimbinganTAModel bimbingan = new BimbinganTAModel();
            ArrayList RataPertemuanPerPeriode = new ArrayList();

            for(int i=0; i < periodeYudisium.size(); i++){

                double RataPertemuan = bimbingan.RataPertemuan(periodeYudisium.get(i).getTglMulai(), periodeYudisium.get(i).getTglAkhir());

                Map map = new HashMap();
                map.put("periode", periodeYudisium.get(i).getPeriode());
                map.put("tglMulai", periodeYudisium.get(i).getTglMulai());
                map.put("tglAkhir", periodeYudisium.get(i).getTglAkhir());
                map.put("RataPertemuan", RataPertemuan);

                RataPertemuanPerPeriode.add(map);  
            }

            request.setAttribute("RataPertemuanPerPeriode", RataPertemuanPerPeriode);
            request.setAttribute("laporan", laporan);
            request.setAttribute("rentangPeriode", rentangPeriode);

            return "monta/RataPertemuanPerPeriode.jsp";   
        }
    }
    
    public String detailPertemuanBim(){
        
        HttpSession session = request.getSession();
        ArrayList ListRole = new ArrayList();
        ListRole = (ArrayList) session.getAttribute("role");
        
        boolean bukanRole = true;
        if (session.getAttribute("role") != null) {
            for (int i = 0; i < ListRole.size(); i++) {
                if ((ListRole.get(i).equals("koordinator_ta"))) {
                    bukanRole = false;
                }
            }
        }
        
        if (session.getAttribute("role") == null) {
            return "login";
        } else if (bukanRole) {
            request.setAttribute("menu", "monitoringTA");
            request.setAttribute("submenu", "");
            return "AccessDenied";
        }else {
            
            String laporan = request.getParameter("laporan");
            String detail = request.getParameter("detail");
            String periode = request.getParameter("periode");
            String periodeRekapAwal = request.getParameter("periodeRekapAwal");
            String periodeRekapAkhir = request.getParameter("periodeRekapAkhir");

            MahasiswaModel mahasiswa = new MahasiswaModel();
            List<Mahasiswa> namaMahasiswa = mahasiswa.ListMahasiswa();

            BimbinganTAModel bimbinganTA = new BimbinganTAModel();
//            List<TA> listPertemuanBim = bimbinganTA.ListJlhPertemuan(periodeRekapAwal, periodeRekapAkhir);
            ArrayList listPertemuanBim = bimbinganTA.ListJlhPertemuan(periodeRekapAwal, periodeRekapAkhir);
            
            request.setAttribute("namaMahasiswa", namaMahasiswa);
            request.setAttribute("listPertemuanBim", listPertemuanBim);
            request.setAttribute("periode", periode);
            request.setAttribute("laporan", laporan);
            request.setAttribute("detail", detail);
            request.setAttribute("periodeRekapAwal", periodeRekapAwal);
            request.setAttribute("periodeRekapAkhir", periodeRekapAkhir);
            
            return "monta/DetailPertemuanBim.jsp";
        } 
    }
}
